package likou;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/08/21 08:25
 */
public class _198 {
    public int rob(int[] nums) {
        int[] res = new int[nums.length];
        for (int i=0;i<nums.length;i++){
            res[i] = nums[i];
            if (i>0) res[i] = Math.max(res[i-1],res[i]);
            if (i>1) res[i] = Math.max(nums[i]+res[i-2],res[i]);
            if (i>2) res[i] = Math.max(nums[i]+res[i-3],res[i]);
        }
        return res[nums.length-1];
    }
}
